package com.lmiot.xyclick.Share;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.lmiot.xyclick.App.MyApp;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Util.ActivityUtil;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.EditDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.xiaoyi.intentsdklibrary.Bean.ShareBeanSqlUtil;
import com.youyi.yyviewsdklibrary.View.TitleBarView;
import java.util.ArrayList;
import java.util.List;

public class ShareFragment extends Fragment implements View.OnClickListener {
    private static final String TAG = "ShareFragment";
    Activity mActivity;
    private Context mContext;
    private List<Fragment> mFragmentList;
    ImageView mIdSearch;
    TitleBarView mIdTitleBar;
    ViewPager mIdViewpager;
    private ShareTypeEnum[] mShareTypeEnums;
    TabLayout mTabLayout;
    private View mView;

    public ShareFragment() {
    }

    public ShareFragment(Context context) {
        this.mContext = context;
    }

    @Override // android.support.v4.app.Fragment
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.mActivity = activity;
    }

    public Activity getMyActivity() {
        return this.mActivity;
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View view = this.mView;
        if (view != null) {
            ViewGroup viewGroup2 = (ViewGroup) view.getParent();
            if (viewGroup2 != null) {
                viewGroup2.removeView(this.mView);
            }
            this.mView = null;
        }
        if (this.mContext == null) {
            this.mContext = getMyActivity();
        }
        View inflate = View.inflate(this.mContext, R.layout.fragment_share, null);
        this.mView = inflate;
        this.mIdTitleBar = (TitleBarView) inflate.findViewById(R.id.id_title_bar);
        this.mIdSearch = (ImageView) this.mView.findViewById(R.id.id_search);
        this.mTabLayout = (TabLayout) this.mView.findViewById(R.id.tab_layout);
        this.mIdViewpager = (ViewPager) this.mView.findViewById(R.id.id_viewpager);
        this.mIdSearch.setOnClickListener(this);
        setTitle();
        ShareBeanSqlUtil.getInstance().delAll();
        setPager();
        return this.mView;
    }

    private void setPager() {
        this.mFragmentList = new ArrayList();
        ShareTypeEnum[] values = ShareTypeEnum.values();
        this.mShareTypeEnums = values;
        for (ShareTypeEnum shareTypeEnum : values) {
            this.mFragmentList.add(new ShareFragmentDetail(this.mContext, shareTypeEnum));
        }
        this.mIdViewpager.setAdapter(new MyPagerAdpater(getChildFragmentManager()));
        this.mTabLayout.setupWithViewPager(this.mIdViewpager);
        this.mTabLayout.setTabTextColors(getResources().getColor(R.color.text_gray), getResources().getColor(R.color.colorAccent));
        this.mIdViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            /* class com.lmiot.xyclick.Share.ShareFragment.AnonymousClass1 */

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageScrollStateChanged(int i) {
            }

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageScrolled(int i, float f, int i2) {
            }

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageSelected(int i) {
                LogUtil.d(ShareFragment.TAG, "onPageSelected:" + i);
            }
        });
    }

    public void onClick(View view) {
        if (view.getId() == R.id.id_search) {
            this.mContext.startActivity(new Intent(this.mContext, SearchShareActivity.class));
        }
    }

    /* access modifiers changed from: private */
    public class MyPagerAdpater extends FragmentPagerAdapter {
        @Override // android.support.v4.app.FragmentPagerAdapter, android.support.v4.view.PagerAdapter
        public void destroyItem(ViewGroup viewGroup, int i, Object obj) {
        }

        public MyPagerAdpater(FragmentManager fragmentManager) {
            super(fragmentManager);
        }

        @Override // android.support.v4.app.FragmentPagerAdapter
        public Fragment getItem(int i) {
            return (Fragment) ShareFragment.this.mFragmentList.get(i);
        }

        @Override // android.support.v4.view.PagerAdapter
        public CharSequence getPageTitle(int i) {
            return ShareFragment.this.mShareTypeEnums[i].getName();
        }

        @Override // android.support.v4.view.PagerAdapter
        public int getCount() {
            return ShareFragment.this.mShareTypeEnums.length;
        }
    }

    @Override // android.support.v4.app.Fragment
    public void onResume() {
        super.onResume();
        this.mIdViewpager.setCurrentItem(0);
    }

    private void setTitle() {
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            /* class com.lmiot.xyclick.Share.ShareFragment.AnonymousClass2 */

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
                if (!MyApp.getInstance().checkLogin(ShareFragment.this.mContext)) {
                    ShareSDK.getInstance().uploadTipDialog(ShareFragment.this.mContext, new OnBasicListener() {
                        /* class com.lmiot.xyclick.Share.ShareFragment.AnonymousClass2.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                            if (z) {
                                ActivityUtil.skipActivity(ShareFragment.this.mContext, UploadShareActivity.class);
                            }
                        }
                    });
                }
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
                if (!MyApp.getInstance().checkLogin(ShareFragment.this.mContext)) {
                    ShareFragment.this.showMenu();
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showMenu() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.share_my, "我的上传", null));
        arrayList.add(new EditDialogUtil.MenuBean(R.drawable.share_fen, "赚取积分", "剩余：" + DataUtil.getShareFen(this.mContext) + "积分"));
        EditDialogUtil.getInstance().buttomMenuDialog(this.mContext, 5, arrayList, new EditDialogUtil.OnMenuClickListener() {
            /* class com.lmiot.xyclick.Share.ShareFragment.AnonymousClass3 */

            @Override // com.lmiot.xyclick.Util.EditDialogUtil.OnMenuClickListener
            public void click(int i) {
                if (i == 0) {
                    ActivityUtil.skipActivity(ShareFragment.this.mContext, ShareSelfActivity.class);
                } else if (i == 1) {
                    ShareSDK.getInstance().addPoint(ShareFragment.this.mContext, new OnBasicListener() {
                        /* class com.lmiot.xyclick.Share.ShareFragment.AnonymousClass3.AnonymousClass1 */

                        @Override // com.lmiot.xyclick.inteface.OnBasicListener
                        public void result(boolean z, String str) {
                        }
                    });
                }
            }
        }, false, false);
    }

    @Override // android.support.v4.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
    }
}
